package com.zx.dsptuneup_TriMic.ProtocolTools;

import com.zx.dsptuneup_TriMic.App;
import com.zx.dsptuneup_TriMic.Data_Bean.ChanelBean;
import com.zx.dsptuneup_TriMic.Data_Bean.EqSegmentBean;
import com.zx.dsptuneup_TriMic.Util.Constants;

import java.util.ArrayList;

public class Init {

    private static int[] developChannelArr = {Constants.channelEnum.line1,Constants.channelEnum.line2,
            Constants.channelEnum.line3,Constants.channelEnum.line4,Constants.channelEnum.line5,
            Constants.channelEnum.line6,Constants.channelEnum.line7,Constants.channelEnum.line8,
            Constants.channelEnum.line9,Constants.channelEnum.line10,Constants.channelEnum.line11,
            Constants.channelEnum.line12,Constants.channelEnum.line13,Constants.channelEnum.line14}; // 对应开发者通道数据

    public static void initData1() throws Exception{
        for (int i=0;i<App.getContext().getEqData().getInputChannelArr().size();i++){
            if(i>0){
                break;
            }
            int channelIndex = i;

            ChanelBean chanelBean = App.getContext().getEqData().getInputChannelArr().get(channelIndex);
            ArrayList<EqSegmentBean> eqSegArr = chanelBean.getEqSegArr();
            for (int k=0;k<eqSegArr.size();k++) {
                EqSegmentBean eqSegmentBean = eqSegArr.get(k);

                int frequent = Integer.parseInt(eqSegmentBean.getEqSegName());
                double gain = eqSegmentBean.getGain();
                double q_value = eqSegmentBean.getQvalue();
//            int type = eqSegmentBean.getType();

                Thread.sleep(100);

                App.getContext().getProtocolConversion().setEQ(ProtocolConversion.getFrameId(), Constants.operation_typeEnum.set_device,Constants.element_typeEnum.INPUT,developChannelArr[channelIndex],k,frequent,q_value,gain);
            }

            Thread.sleep(100);
            // 音量
            boolean mute = chanelBean.isMute();
            App.getContext().getProtocolConversion().setMute(ProtocolConversion.getFrameId(), Constants.operation_typeEnum.set_device,Constants.element_typeEnum.INPUT, developChannelArr[channelIndex],mute);


            // 高低切
            Thread.sleep(100);
            App.getContext().getProtocolConversion().setHighLowCut(ProtocolConversion.getFrameId(),Constants.operation_typeEnum.set_device,Constants.element_typeEnum.INPUT,developChannelArr[channelIndex],Constants.highLowCutEnum.high, chanelBean.getHighCut());

            Thread.sleep(100);
            App.getContext().getProtocolConversion().setHighLowCut(ProtocolConversion.getFrameId(),Constants.operation_typeEnum.set_device,Constants.element_typeEnum.INPUT,developChannelArr[channelIndex],Constants.highLowCutEnum.low, chanelBean.getLowCut());

            // volume
            Thread.sleep(100);
            App.getContext().getProtocolConversion().setVolume(ProtocolConversion.getFrameId(), Constants.operation_typeEnum.set_device,Constants.element_typeEnum.INPUT, developChannelArr[channelIndex],chanelBean.getVolume());

//            Thread.sleep(100);
//            initData2();
        }

    }


    private static void initData2() throws Exception{
        for (int i=0;i<App.getContext().getEqData().getOutputChannelArr().size();i++){
            int channelIndex = i;

            ChanelBean chanelBean = App.getContext().getEqData().getOutputChannelArr().get(channelIndex);
            ArrayList<EqSegmentBean> eqSegArr = chanelBean.getEqSegArr();
            for (int k=0;k<eqSegArr.size();k++) {
                EqSegmentBean eqSegmentBean = eqSegArr.get(k);

                int frequent = Integer.parseInt(eqSegmentBean.getEqSegName());
                double gain = eqSegmentBean.getGain();
                double q_value = eqSegmentBean.getQvalue();
//            int type = eqSegmentBean.getType();

                Thread.sleep(100);

                App.getContext().getProtocolConversion().setEQ(ProtocolConversion.getFrameId(), Constants.operation_typeEnum.set_device,Constants.element_typeEnum.OUTPUT,developChannelArr[channelIndex],k,frequent,q_value,gain);
            }

            Thread.sleep(100);
            // 音量
            boolean mute = chanelBean.isMute();
            App.getContext().getProtocolConversion().setMute(ProtocolConversion.getFrameId(), Constants.operation_typeEnum.set_device,Constants.element_typeEnum.OUTPUT, developChannelArr[channelIndex],mute);


            // 高低切
            Thread.sleep(100);
            App.getContext().getProtocolConversion().setHighLowCut(ProtocolConversion.getFrameId(),Constants.operation_typeEnum.set_device,Constants.element_typeEnum.OUTPUT,developChannelArr[channelIndex],Constants.highLowCutEnum.high, chanelBean.getHighCut());

            Thread.sleep(100);
            App.getContext().getProtocolConversion().setHighLowCut(ProtocolConversion.getFrameId(),Constants.operation_typeEnum.set_device,Constants.element_typeEnum.OUTPUT,developChannelArr[channelIndex],Constants.highLowCutEnum.low, chanelBean.getLowCut());

            // volume
            Thread.sleep(100);
            App.getContext().getProtocolConversion().setVolume(ProtocolConversion.getFrameId(), Constants.operation_typeEnum.set_device,Constants.element_typeEnum.OUTPUT, developChannelArr[channelIndex],chanelBean.getVolume());
        }


    }
}
